import { Dialog, Image, Toast } from "@antmjs/vantui";
import { useState, useImperativeHandle, forwardRef } from "react";
import Taro from "@tarojs/taro";

const CusModal = forwardRef(({ url, }, ref) => {

    const [show, setShow] = useState(false)

    useImperativeHandle(ref, () => ({
        show: () => {
            setShow(true)
        },

        close: () => {
            setShow(false)
        }
    }))

    return (
        <Dialog onConfirm={()=>{
            Taro.saveImageToPhotosAlbum({filePath:url},{
                success: function (res) {
                    Toast.success({message:'保存成功'})
                 }
              })
        }} confirmButtonText={"保存图片"} show={show} onClose={() => setShow(false)}>
            <Image height={url&&(url.indexOf('gongzhouhao')==-1||url.indexOf('wechat'))==-1?240:700} width={'100%'} src={url} />
        </Dialog>
    )
})


export default CusModal